﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using _23_Command.紧耦合设计;

namespace _23_Command.松耦合设计
{
    public abstract class Command
    {
        protected Barbecuer receiver;

        public Command(Barbecuer receiver)
        {
            this.receiver = receiver;
        }

        //执行命令
        abstract public void ExcuteCommand();
    }

    public class BakeMuttonCommand : Command
    {
        public BakeMuttonCommand(Barbecuer receiver) : base(receiver)
        {
        }
        public override void ExcuteCommand()
        {
            receiver.BakeMutton();
        }
    }

    public class BakeChickenCommand : Command
    {
        public BakeChickenCommand(Barbecuer receiver) : base(receiver)
        {
        }
        public override void ExcuteCommand()
        {
            receiver.BakeChickenWings();
        }
    }

    public class Waiter
    {
        private List<Command> commands = new List<Command>();
        public void SetOrder(Command command)
        {
            commands.Add(command);
        }
        public void Cancle(Command command)
        {
            commands.Remove(command);
        }
        public void Notify()
        {
            foreach (var command in commands)
            {
                command.ExcuteCommand();
            }
            commands.Clear();
        }
    }
}
